package com.xiaochong.tir.common.data.po;


import com.alibaba.fastjson.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class Navigation implements Serializable {

    private Integer id;

    private String title;

    private String icon;

    private Boolean spread;

    private String href;

    private Integer parentId;

    private Integer status;

    private Date createTime;

    private Date updateTime;

    private Integer rank;
    
    private Integer roleId;
    
    private Integer count;
    

    public Integer getCount() {
		return count;
	}

	public void setCount(Integer count) {
		this.count = count;
	}

	public Integer getRoleId() {
		return roleId;
	}

	public void setRoleId(Integer roleId) {
		this.roleId = roleId;
	}

	private static final long serialVersionUID = 1L;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title == null ? null : title.trim();
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon == null ? null : icon.trim();
    }

    public Boolean getSpread() {
        return spread;
    }

    public void setSpread(Boolean spread) {
        this.spread = spread;
    }

    public String getHref() {
        return href;
    }

    public void setHref(String href) {
        this.href = href == null ? null : href.trim();
    }

    public Integer getParentId() {
        return parentId;
    }

    public void setParentId(Integer parentId) {
        this.parentId = parentId;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Integer getRank() {
        return rank;
    }

    public void setRank(Integer rank) {
        this.rank = rank;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", title=").append(title);
        sb.append(", icon=").append(icon);
        sb.append(", spread=").append(spread);
        sb.append(", href=").append(href);
        sb.append(", parentId=").append(parentId);
        sb.append(", status=").append(status);
        sb.append(", createTime=").append(createTime);
        sb.append(", updateTime=").append(updateTime);
        sb.append(", rank=").append(rank);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }

    public JSONObject toJSONObject(){
        JSONObject jsonObject = new JSONObject();
        if (title != null){
            jsonObject.put("title", title);
        }
        if (icon != null){
            jsonObject.put("icon", icon);
        }
        if (spread != null){
            jsonObject.put("spread", spread);
        }
        if (href != null){
            jsonObject.put("href", href);
        }
        if (list != null && !list.isEmpty()){
            jsonObject.put("children", list);
        }
        return jsonObject;
    }

    private List<JSONObject> list;

    public List<JSONObject> getList() {
        return list;
    }

    public void setList(List<JSONObject> list) {
        this.list = list;
    }

    public synchronized void addChildren(Navigation navigation){
        if (navigation == null){
            return;
        }
        if (list == null){
            list = new ArrayList<>();
        }
        list.add(navigation.toJSONObject());
    }

}